package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.course.CourseOrder;
import com.hualan.sfzy.service.course.CourseOrderService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CourseOrderController {
    @Autowired
    private CourseOrderService courseOrderService;
    @PostMapping("/courseOrder")
    public Result add(@RequestBody CourseOrder courseOrder) {
        return courseOrderService.add(courseOrder)>0? Result.success():Result.error();
    }
    @PutMapping("/courseOrder")
    public Result update(@RequestBody CourseOrder courseOrder) {
        return courseOrderService.edit(courseOrder)>0?Result.success():Result.error();
    }
    @DeleteMapping("/courseOrder")
    public Result remove(Integer[] ids) {
        return courseOrderService.removeBatch(ids)>0?Result.success():Result.error();
    }
    @DeleteMapping("/courseOrder/{id}")
    public Result removeBatch(@PathVariable Integer id) {
        return courseOrderService.remove(id)>0?Result.success():Result.error();
    }
    @GetMapping("/courseOrder/{id}")
    public Result findById(@PathVariable Integer id) {
        CourseOrder courseOrder = courseOrderService.findById(id);
        return Result.success(courseOrder);
    }
    @GetMapping("/courseOrder")
    public Result find() {
        List<CourseOrder> list = courseOrderService.find();
        return Result.success(list);
    }
    @GetMapping("/courseOrder/page")
    public Result findByPage(
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")
            Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "5")
            Integer pageSize,
            CourseOrder courseOrder) {
        Map<String,Object> map = courseOrderService.findByPage(pageNum, pageSize, courseOrder);
        return Result.success(map);
    }

    @GetMapping("/courseOrder1")
    public Result getCourseOrders(@RequestParam Integer userId,
                                  @RequestParam Integer courseId) {
        List<CourseOrder> orders = courseOrderService.getCourseOrders(userId, courseId);
        return Result.success(orders);
    }
}

